module.exports = {
	/**
	 * 添加单条数据
	 * @url admin/pages/kh/copyright/copyright_account_number//add 前端调用的url参数地址
	 * data 请求参数 说明
	 * res 返回参数说明
	 * @params {Number} code 错误码，0表示成功
	 * @params {String} msg 详细信息
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: 'ok' };
		// 业务逻辑开始-----------------------------------------------------------
		// 获取前端传过来的参数
		let {
			bank,
			paymentAccount,
			paymentCompany,
			username,
			password,
			password_secret_version,
			nickname,
			commission_rate,
			role,
			remark,
			appid,
			appname,
			array_copyright//版权方绑定剧和佣金数据
		} = data;
		// 参数验证开始

		/**
		 * 判断数据库是否已存在该用户名
		 */
		// if (appid==null) {
		// 	res.code=-1
		// 	res.msg='请绑定小程序'
		// 	return res
		// }
		// if (commission_rate * 1 < 0 || commission_rate * 1 > 1) {
		// 	res.code = 1;
		// 	res.msg = "佣金比例设置错误";
		// 	return res;
		// }

		let check_username = await db.collection('uni-id-users').where({
			username: username
		}).count()
		if (check_username.total > 0) {
			res = {
				code: 1,
				msg: "已存在此用户名"
			};
			return res;
		}


		// 参数验证结束
		let dbName = "uni-id-users"; // 表名
		// 执行 数据库add 命令
		res.id = await vk.baseDao.add({
			dbName,
			dataJson: {
				bank,
				paymentAccount,
				paymentCompany,
				array_copyright,
				username,
				password:"03caebb36670995fc261a275d212cad65e4bbebd",
				password_secret_version,
				nickname,
				commission_rate: commission_rate,
				role:["copyright"],
				remark,
				allow_login_background: true,
			}
		});
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
